#define _CRT_SECURE_NO_WARNINGS -1

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main()
{
    int input = 0;
    int mode = 0;
    int flag = 0;
    scanf("%d %d", &input, &mode);
    if (input < 0)
        flag = 1;
    input = abs(input);
    char key[] = { '1','2', '3', '4', '5', '6', '7', '8','9', 'A', 'B', 'C','D','E','F' };
    string result;
    while (input)
    {
        result.insert(result.begin(), key[input % mode - 1]);
        input /= mode;
    }
    if (flag)
        result.insert(result.begin(), '-');
    cout << result << endl;
    return 0;
}